<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">


<!-- Central Body -->
<xsl:template match="Container">  
import javax.swing.*;
import java.awt.*;
        
public class <xsl:value-of select="@title"/> extends <xsl:value-of select="@type"/>{

	private static final long serialVersionUID = 1L;

	public static void main(String args[]) {
		new <xsl:value-of select="@title"/>();
	}

	<xsl:value-of select="@title"/>() {
			
		this.setSize(<xsl:value-of select="@size"/>);
		addComponentsToPane(this.getContentPane());
		pack();
		setVisible(<xsl:value-of select="@visible"/>);
	}
	
	public static void addComponentsToPane(Container <xsl:value-of select="@id"/>) {
		//Dichiarazione struttura del Layout del container principale 
		<xsl:apply-templates select="child::Layout" />
		//Dichiarazione Panelli e relativi layout
		<xsl:apply-templates select="//Panel" />    
		//Dichiarazione Label 
        <xsl:apply-templates select="//JLabel" />
        //Dichiarazione Button	
		<xsl:apply-templates select="//JButton" />	
		//Dichiarazione TextField	
		<xsl:apply-templates select="//JTextField" />
		//Dichiarazione JPasswordField	
		<xsl:apply-templates select="//JPasswordField" />	
		//Dichiarazione JComboBox	
		<xsl:apply-templates select="//JComboBox" />	
		//Dichiarazione JTextArea	
		<xsl:apply-templates select="//JTextArea" />
	}	
}
</xsl:template>

<!-- Layout -->
<xsl:template match="Layout">	
	<xsl:choose>		
		<xsl:when test="@param1">	
		<xsl:value-of select="@type"/><xsl:text> </xsl:text><xsl:value-of select="@id"/> = new <xsl:value-of select="@type"/>(<xsl:value-of select="parent::*/@id"/>, <xsl:value-of select="@type"/>.<xsl:value-of select="@param1"/>);
		</xsl:when>
		<xsl:otherwise>
		<xsl:value-of select="@type"/><xsl:text> </xsl:text><xsl:value-of select="@id"/> = new <xsl:value-of select="@type"/>();
		</xsl:otherwise>
		</xsl:choose>	
		<xsl:value-of select="parent::*/@id"/>.setLayout(<xsl:value-of select="@id"/>);
</xsl:template>


<!-- Panel -->
<xsl:template match="Panel">			
		<xsl:value-of select="@type"/><xsl:text> </xsl:text><xsl:value-of select="@id"/> = new <xsl:value-of select="@type"/>();				
		<xsl:choose>		
		<xsl:when test="@align">
		<xsl:value-of select="ancestor::*/@id"/>.add(<xsl:value-of select="@id"/>,<xsl:value-of select="(parent::node())/@type"/>.<xsl:value-of select="@align"/>);
		</xsl:when>
		<xsl:otherwise>
		<xsl:value-of select="ancestor::*/@id"/>.add(<xsl:value-of select="@id"/>);		
		</xsl:otherwise>	
		</xsl:choose>	
		<xsl:apply-templates select="child::Layout" />
</xsl:template>


<!-- Label -->
<xsl:template match="JLabel">			
		JLabel <xsl:value-of select="@id"/> = new JLabel("<xsl:value-of select="@text"/>");					
		<xsl:choose>		
		<xsl:when test="@align">
		<xsl:value-of select="ancestor::Panel/@id"/>.add(<xsl:value-of select="@id"/>,<xsl:value-of select="(parent::node())/@type"/>.<xsl:value-of select="@align"/>);
		</xsl:when>
		<xsl:otherwise>
		<xsl:value-of select="ancestor::Panel/@id"/>.add(<xsl:value-of select="@id"/>);		
		</xsl:otherwise>
		</xsl:choose>	
</xsl:template>

<!-- TextField -->
<xsl:template match="JTextField">			
		JTextField <xsl:value-of select="@id"/> = new JTextField(<xsl:value-of select="@size"/>);					
		<xsl:choose>		
		<xsl:when test="@align">
		<xsl:value-of select="ancestor::Panel/@id"/>.add(<xsl:value-of select="@id"/>,<xsl:value-of select="(parent::node())/@type"/>.<xsl:value-of select="@align"/>);
		</xsl:when>
		<xsl:otherwise>
		<xsl:value-of select="ancestor::Panel/@id"/>.add(<xsl:value-of select="@id"/>);		
		</xsl:otherwise>
		</xsl:choose>	
</xsl:template>

<!-- JPasswordField -->
<xsl:template match="JPasswordField">			
		JPasswordField <xsl:value-of select="@id"/> = new JPasswordField(<xsl:value-of select="@size"/>);					
		<xsl:choose>		
		<xsl:when test="@align">
		<xsl:value-of select="ancestor::Panel/@id"/>.add(<xsl:value-of select="@id"/>,<xsl:value-of select="(parent::node())/@type"/>.<xsl:value-of select="@align"/>);
		</xsl:when>
		<xsl:otherwise>
		<xsl:value-of select="ancestor::Panel/@id"/>.add(<xsl:value-of select="@id"/>);		
		</xsl:otherwise>
		</xsl:choose>	
</xsl:template>

<!-- JComboBox -->
<xsl:template match="JComboBox">	
		String[] <xsl:value-of select="@id"/>Content = {""<xsl:for-each select="child::Element">,"<xsl:value-of select="@text"/>"</xsl:for-each>};		
		JComboBox <xsl:value-of select="@id"/> = new JComboBox(<xsl:value-of select="@id"/>Content);					
		<xsl:choose>		
		<xsl:when test="@align">
		<xsl:value-of select="ancestor::Panel/@id"/>.add(<xsl:value-of select="@id"/>,<xsl:value-of select="(parent::node())/@type"/>.<xsl:value-of select="@align"/>);
		</xsl:when>
		<xsl:otherwise>
		<xsl:value-of select="ancestor::Panel/@id"/>.add(<xsl:value-of select="@id"/>);		
		</xsl:otherwise>
		</xsl:choose>	
</xsl:template>

<!-- JButton -->
<xsl:template match="JButton">		
		<xsl:choose>				
		<xsl:when test="@icon">
		JButton <xsl:value-of select="@id"/> = new JButton("<xsl:value-of select="@icon"/>");
		</xsl:when>
		<xsl:when test="@icon and @text">
		JButton <xsl:value-of select="@id"/> = new JButton("<xsl:value-of select="@text"/>","<xsl:value-of select="@icon"/>");
		</xsl:when>
		<xsl:otherwise>
		JButton <xsl:value-of select="@id"/> = new JButton("<xsl:value-of select="@text"/>");
		</xsl:otherwise>									
		</xsl:choose>
		<xsl:choose>		
		<xsl:when test="@align">
		<xsl:value-of select="ancestor::Panel/@id"/>.add(<xsl:value-of select="@id"/>,<xsl:value-of select="(parent::node())/@type"/>.<xsl:value-of select="@align"/>);
		</xsl:when>
		<xsl:otherwise>
		<xsl:value-of select="ancestor::Panel/@id"/>.add(<xsl:value-of select="@id"/>);		
		</xsl:otherwise>
		</xsl:choose>	
</xsl:template>

<!-- TextArea -->
<xsl:template match="JTextArea">		
		<xsl:choose>
		<xsl:when test="@row and @col and @text">
		JTextArea <xsl:value-of select="@id"/> = new JTextArea("<xsl:value-of select="@text"/>",<xsl:value-of select="@row"/>,<xsl:value-of select="@col"/>);
		</xsl:when>
		<xsl:when test="@text">
		JTextArea <xsl:value-of select="@id"/> = new JTextArea("<xsl:value-of select="@text"/>");		
		</xsl:when>				
		<xsl:when test="@row and @col">
		JTextArea <xsl:value-of select="@id"/> = new JTextArea(<xsl:value-of select="@row"/>,<xsl:value-of select="@col"/>);		
		</xsl:when>
		
		<xsl:otherwise>
		JTextArea <xsl:value-of select="@id"/> = new JTextArea();
		</xsl:otherwise>									
		</xsl:choose>	
					
		<xsl:choose>		
		<xsl:when test="@align">
		<xsl:value-of select="ancestor::Panel/@id"/>.add(<xsl:value-of select="@id"/>,<xsl:value-of select="(parent::node())/@type"/>.<xsl:value-of select="@align"/>);
		</xsl:when>
		<xsl:otherwise>
		<xsl:value-of select="ancestor::Panel/@id"/>.add(<xsl:value-of select="@id"/>);		
		</xsl:otherwise>
		</xsl:choose>	
</xsl:template>
    
<xsl:output
  method = "text"
  encoding = "UTF-8"
  omit-xml-declaration = "yes" 
  standalone = "yes" 
  cdata-section-elements = "Jlabel Panel Layout JButton"
  indent = "yes" 
  media-type = "String" />
</xsl:stylesheet>